package org.sss.mapreduce.example;

import org.sss.client.Job;
import org.sss.client.JobEngine;
import org.sss.client.SssClient;
import org.sss.mapreduce.GroupID;
import org.sss.mapreduce.HashPartitioner2;

public class VacuumRunner {
  /**
   * Usage:
   * java VacuumRunner commid
   */
  public static void main(String[] args) throws Exception {
    SssClient client = new SssClient(args);
    String[] others = client.getArgs();
    String input = null;
    if (others.length < 1) {
      System.err.println("input communicator id is not specified.");
      System.exit(-1);
    }
    else if (others.length > 1) {
      System.err.println("too many arguments.");
      System.exit(-1);
    }
    else {                      // others.length == 1
      input = others[0];
    }
    JobEngine engine = new JobEngine(client);
    try {
      GroupID ci = GroupID.createFromString(input);
      GroupID co = GroupID.createRandom(engine);
      Job.Builder b = engine.getJobBuilder("jobVM", VacuumMapper.class);
      b.addInput(ci).addOutput(co, Job.partitioner(HashPartitioner2.class));
      @SuppressWarnings("unused")
      Job j = b.build();
      engine.exec();
      System.out.println(co);
    }
    finally {
      engine.dispose();
    }
  }
}
